#ifndef TREVENTNODE_H
#define TREVENTNODE_H

/*
interface used in the messaging
system. events are enums.
based peers
*/

#include <irrlicht.h>
#include "trEvent.h"

namespace tetra
{

class trGameObject;


//mode for reading and writing the event_cache
enum EPROBE_CACHE_MODE
{

    E_NULL

};

class trEventNode;

typedef irr::core::array<trEventNode*> trEventNodeArray;
typedef irr::core::array<trEvent*> trEventArray;

class trEventNode : public irr::IReferenceCounted
{

    irr::u32 number_peers; //number of peers
    irr::u32 number_events; //number of events in cache
    irr::u32 number_events_long; //number of events in long cache

    trEventNodeArray* peers;

    //short term and long term event cache
    trEventArray* event_cache;
    trEventArray* event_cache_long;

public:

    //! Default constructor
    trEventNode();

    //! Constructor
    trEventNode( trEventNodeArray* new_peers, trEventArray* events_to_cache, trEventArray* events_to_cache_long );

    //! Destructor
    ~trEventNode();

    ///@note on proccesing events according to trGRS protocol methodology
    /// there should not be an excessive number of events in the main or
    /// "short term" event cache. too many and it will slow performance down
    ///when doing searches
    ///for "long term" events such as long timers, trState associated events or
    /// redundant events, use the second event cahce event_cache_long

    //! Broadcast event to specified peers
    void broadcastEvent( trEvent* event, trEventNodeArray* target );

    //! Stores pointer to event in event_cache
    // 0 - id for event_cache
    // 1 - id for event_cache_long
    // 2 - id for event_cache and event_cache_long
    void cacheEvent( trEvent* event, irr::u32 cache );

    //! Method for testing events in event_cache
    // 0 - id for event_cache
    // 1 - id for event_cache_long
    // 2 - id for event_cache and event_cache_long
    bool onEvent( trEvent* event, tetra::trGameProperty* prop, irr::u32 cache ) const;

    //! Method for testing events in event_cache
    /// based on ETR_EVENT type and trGameProperty data match
    // 0 - id for event_cache
    // 1 - id for event_cache_long
    // 2 - id for event_cache and event_cache_long
    irr::u32 onEvent( trEventType* event_type, EPROBE_CACHE_MODE mode, irr::u32 cache ) const;

    //! Removes trEvent pointer from event_cache
    //! Expensive. Instead use a 'first in last out'& popping method to process events.
    // 0 - id for event_cache
    // 1 - id for event_cache_long
    // 2 - id for event_cache and event_cache_long
    void removeEvent( trEvent* event, irr::u32 cache ) const;

};

}; //end namespace tetra

#endif //TREVENTNODE_H
